package cn.xiaoniu.day03;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.InputStreamReader;

import cn.xiaoniu.day03.utils.Utils;

/**
 * 删除掉不需要的字段，把经纬度信息转换为一维数据
 * @author root
 *
 */
public class Repostory {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream("d:\\data\\bj-poi-1.csv"), "gbk"));//csv使用逗号分隔数据的，   tsv使用tab键分隔的
		BufferedWriter bw = new BufferedWriter(new FileWriter("D:\\data\\repostory.txt"));
		String line = null;
		//跳过表头
		br.readLine();
		
		//中羊坊3区49号楼,地名地址信息;门牌信息;楼栋号,115.972615,40.515135,北京市延庆区中羊坊三区117号楼,北京市,10,延庆区,旧小路,110119,190403,延庆区,115.9664995,40.51388848,115.9792141,40.52080807
		while((line=br.readLine())!=null){
			try {
				//System.out.println(line);
				String[] split = line.split(",");
				String addr = split[0];
				double localx = Double.parseDouble(split[2]);//经度
				double localy = Double.parseDouble(split[3]);//维度
				String city = split[5];
				String district = split[7];
				
				//geohash转换
				String geoHash = Utils.getGeoHash(localy, localx);
				//8329ea 北京省 北京市 xx区 xx地方
				String ret = geoHash+"\t北京市\t"+city+"\t"+district+"\t"+addr;
				bw.write(ret);
				bw.newLine();
			} catch (Exception e) {
				// TODO: handle exception
			}
			
			
		}
		bw.flush();
		bw.close();
		br.close();
		System.out.println("over!!!");
		
		
	}
}
